package com.example.recyclerviewtest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.example.recyclerviewtest.adapter.MyAdapter;
import com.example.recyclerviewtest.bean.Infos;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recycler =null;
    private GridLayoutManager manager =null;
    private MyAdapter adapter =null;
    private List<Infos> lists =null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lists =new ArrayList<Infos>();
        for (int i=0;i<100;i++){
            Infos info =new Infos();
            info.setTitle("title"+i);
            info.setAuthor("author"+i);
            info.setLove(i);
            lists.add(info);
        }
        recycler =findViewById(R.id.recycler);
        manager =new GridLayoutManager(this,2);
        adapter =new MyAdapter(this);
        adapter.setData(lists);
        recycler.setLayoutManager(manager);
        recycler.setAdapter(adapter);
    }
}